package com.qffx.moviebase.adapter.classify;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qffx.moviebase.R;
import com.qffx.moviebase.bean.classify.ClassifyEntity;
import com.qffx.moviebase.view.classify.SpecialWebviewActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lenovo on 2017/2/8.
 */

public class ClassifySpeacialAdapter extends RecyclerView.Adapter<ClassifySpeacialAdapter.ViewHolder> {
    private List<ClassifyEntity.TopicRecommendListBean> list;
    private LayoutInflater inflater;
    private Context context;

    public ClassifySpeacialAdapter(List<ClassifyEntity.TopicRecommendListBean> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_speacial_iv, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        Picasso.with(context).load(list.get(position).getImgUrl()).into(holder.iv);
        holder.tv1.setText(list.get(position).getTitle());
        holder.tv2.setText(list.get(position).getArticlesNum()+"");
        holder.tv3.setText(list.get(position).getSubscribeNum()+"");
        holder.tvClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, SpecialWebviewActivity.class);
                intent.putExtra("url","http://www.moviebase.cn/uread/app/topic/shareViewTopic-"+list.get(position).getId()+".html");
                context.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv1, tv2, tv3;
        private LinearLayout tvClick;

        public ViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.class_speacial_iv);
            tv1 = (TextView) itemView.findViewById(R.id.class_speacial_tv1);
            tv2 = (TextView) itemView.findViewById(R.id.class_speacial_tv2);
            tv3 = (TextView) itemView.findViewById(R.id.class_speacial_tv3);
            tvClick= (LinearLayout) itemView.findViewById(R.id.speacial_click);
        }
    }


}
